package demo.demo09;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class test03 {
    public static void main(String[] args) {
        Frame frame = new Frame("JAVA Frame With Panel");
        Panel panel = new Panel(null);
        frame.setLayout(null);
//        这里设置的坐标(300, 300) 是相对于整个屏幕的
        frame.setBounds(300, 300, 500, 500);
//        设置背景颜色时使用三基色(红，绿，蓝) 的比例来调配背景色
        frame.setBackground(new Color(0, 0, 102));
//        这里设置的坐标(50, 50) 是相对于Frame窗体的
        panel.setBounds(50, 50, 400, 400);
        panel.setBackground(new Color(204, 204, 255));
//        把Panel容器装入到Frame容器中，使其能在Frame窗口中显示出来
        frame.add(panel);
        frame.setVisible(true);
//        解决关闭问题
        frame.addWindowListener(new WindowListener() {
            @Override
            public void windowOpened(WindowEvent e) {
            }

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

            @Override
            public void windowClosed(WindowEvent e) {
            }

            @Override
            public void windowIconified(WindowEvent e) {
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
            }

            @Override
            public void windowActivated(WindowEvent e) {
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
            }
        });
    }
}